package com.lsf.dunlian.config;

import android.content.Context;
import android.content.SharedPreferences;

import com.lsf.dunlian.Myappliction;


/**
 * Created by 10109 on 2018/1/1.
 */
public class PreferenceUtil {

    public static void putSharedPreference(String key, Object object) {
        SharedPreferences sp = Myappliction.mainActivity.getSharedPreferences(Myappliction.mainActivity.getPackageName(), Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        //   if (object instanceof String) {
        editor.putString(key, (String) object);
//        } else if (object instanceof Integer) {
//            editor.putInt(key, (Integer) object);
//        } else if (object instanceof Boolean) {
//            editor.putBoolean(key, (Boolean) object);
//        } else if (object instanceof Float) {
//            editor.putFloat(key, (Float) object);
//        } else if (object instanceof Long) {
//            editor.putLong(key, (Long) object);
//        } else {
//            editor.putString(key, object.toString());
//        }
        editor.commit();
    }


    public static String getSharedPreference(String key) {
        SharedPreferences sp = Myappliction.mainActivity.getSharedPreferences(Myappliction.mainActivity.getPackageName(), Context.MODE_PRIVATE);
        //       if (defaultObject instanceof String) {
        return sp.getString(key, "");
//        } else if (defaultObject instanceof Integer) {
//            return sp.getInt(key, (Integer) defaultObject);
//        } else if (defaultObject instanceof Boolean) {
//            return sp.getBoolean(key, (Boolean) defaultObject);
//        } else if (defaultObject instanceof Float) {
//            return sp.getFloat(key, (Float) defaultObject);
//        } else if (defaultObject instanceof Long) {
//            return sp.getLong(key, (Long) defaultObject);
//        }
        //      return null;
    }

//    public static boolean getBooleanSharedPreference(String key){
//        SharedPreferences sp = Myappliction.getContext().getSharedPreferences(Myappliction.getContext().getPackageName(), Context.MODE_PRIVATE);
//        return sp.getBoolean(key,false);
//    }
}